<template>
<Input type="text" :readonly="redOnly" :placeholder="redOnly?configuredPlaceholder:placeholder"/>
</template>
<script>
import { ajax} from 'framework'
import { ref} from 'vue'
const allCodes=ref(new Set())
//获取全部已配置的编码，编码表中存在，但未配置规则算未配置
ajax.get('codes/allCodes').then(ret=>{
  allCodes.value = new Set(ret.data)
})
//提供全局判断
export const hasCode=(code)=>{
  return allCodes.value.has(code)
}
export default {
  name:'CodesInput',
  props:{
    code:{
      type:String,
      default:null,
    },
    configured:{
      type:Boolean,
      description:'是否有这个配置规则',
      default:false
    },
    placeholder:{
      type:String,
      default:'',
    },
    configuredPlaceholder:{
      type:String,
      default:'系统自动生成',
    }
  },
  computed:{
    redOnly(){
      let hasCode = allCodes.value.has(this.$props.code)
      this.$emit('update:configured',hasCode)
      return hasCode
    }
  }
}
</script>
